syntax = "proto3";

package kuma.mesh.v1alpha1;

option go_package = "github.com/kumahq/kuma/api/mesh/v1alpha1";

import "envoy/service/discovery/v3/discovery.proto";
import "google/protobuf/any.proto";
import "google/protobuf/duration.proto";

service KumaDiscoveryService {
  rpc StreamKumaResources(stream envoy.service.discovery.v3.DiscoveryRequest)
      returns (stream envoy.service.discovery.v3.DiscoveryResponse);
}

message KumaResource {
  message Meta {
    string name = 1;
    string mesh = 2;
    string version = 5;
    map<string, string> labels = 6;
  }
  Meta meta = 1;
  google.protobuf.Any spec = 2;
}

message ZoneHealthCheckRequest {}

message ZoneHealthCheckResponse {
  // The the interval that the global control plane
  // expects between health check pings
  google.protobuf.Duration interval = 1;
}

service GlobalKDSService {
  // StreamXDSConfigs is logically a service exposed by Zone CP so Global CP can
  // execute Config Dumps. It is however represented by bi-directional streaming
  // to leverage existing connection from Zone CP to Global CP.
  rpc StreamXDSConfigs(stream XDSConfigResponse)
      returns (stream XDSConfigRequest);
  // StreamStats is logically a service exposed by Zone CP so Global CP can
  // execute kuma-dp stats requests. It is however represented by bi-directional
  // streaming to leverage existing connection from Zone CP to Global CP.
  rpc StreamStats(stream StatsResponse) returns (stream StatsRequest);
  // StreamStats is logically a service exposed by Zone CP so Global CP can
  // execute kuma-dp clusters request. It is however represented by
  // bi-directional streaming to leverage existing connection from Zone CP to
  // Global CP.
  rpc StreamClusters(stream ClustersResponse) returns (stream ClustersRequest);
  // HealthCheck allows us to implement a health check that works across
  // proxies, unlike HTTP/2 PING frames.
  rpc HealthCheck(ZoneHealthCheckRequest) returns (ZoneHealthCheckResponse);
}

// KDSSyncService is a service exposed by the control-plane for the
// synchronization of the resources between zone and global control-plane.
service KDSSyncService {
  // GlobalToZoneSync is logically a service exposed by global control-plane
  // that allows zone control plane to connect and synchronize resources from
  // the global control-plane to the zone control-plane. It uses delta xDS from
  // go-control-plane and responds only with the changes to the resources.
  rpc GlobalToZoneSync(stream envoy.service.discovery.v3.DeltaDiscoveryRequest)
      returns (stream envoy.service.discovery.v3.DeltaDiscoveryResponse);
  // ZoneToGlobalSync is logically a service exposed by global control-plane
  // that allows zone control plane to connect and synchronize resources to
  // the global control-plane. It uses delta xDS from go-control-plane and
  // responds only with the changes to the resources.
  rpc ZoneToGlobalSync(stream envoy.service.discovery.v3.DeltaDiscoveryResponse)
      returns (stream envoy.service.discovery.v3.DeltaDiscoveryRequest);
}

// XDSConfigRequest is a request for XDS Config Dump that is executed on Zone
// CP.
message XDSConfigRequest {
  // RequestID is a UUID of a request so we can correlate requests with response
  // on one stream.
  string request_id = 1;

  // Type of resource (Dataplane, ZoneIngress, ZoneEgress)
  string resource_type = 2;
  // Name of the resource on which we execute config dump.
  string resource_name = 3;
  // Mesh of the resource on which we execute config dump. Should be empty for
  // ZoneIngress, ZoneEgress.
  string resource_mesh = 4;
}

// XDSConfigRequest is a response containing result of XDS Config Dump execution
// on Zone CP.
message XDSConfigResponse {
  // RequestID is a UUID that was set by the Global CP.
  string request_id = 1;

  oneof result {
    // Error that was captured by the Zone CP when executing XDS Config Dump.
    string error = 2;
    // The XDS Config that is a successful result of XDS Config dump execution.
    bytes config = 3;
  }
}

// StatsRequest is a request for kuma-dp stats that is executed on Zone CP.
message StatsRequest {
  // RequestID is a UUID of a request so we can correlate requests with response
  // on one stream.
  string request_id = 1;

  // Type of resource (Dataplane, ZoneIngress, ZoneEgress)
  string resource_type = 2;
  // Name of the resource on which we execute kuma-dp stats request.
  string resource_name = 3;
  // Mesh of the resource on which we execute kuma-dp stats request.
  // Should be empty for ZoneIngress, ZoneEgress.
  string resource_mesh = 4;
}

// StatsResponse is a response containing result of kuma-dp stats execution on
// Zone CP.
message StatsResponse {
  // RequestID is a UUID that was set by the Global CP.
  string request_id = 1;

  oneof result {
    // Error that was captured by the Zone CP when executing kuma-dp stats
    // request.
    string error = 2;
    // The stats content that is a successful result of kuma-dp stats execution.
    bytes stats = 3;
  }
}

// ClustersRequest is a request for kuma-dp clusters that is executed on Zone
// CP.
message ClustersRequest {
  // RequestID is a UUID of a request so we can correlate requests with response
  // on one stream.
  string request_id = 1;

  // Type of resource (Dataplane, ZoneIngress, ZoneEgress)
  string resource_type = 2;
  // Name of the resource on which we execute kuma-dp clusters request.
  string resource_name = 3;
  // Mesh of the resource on which we execute kuma-dp clusters request.
  // Should be empty for ZoneIngress, ZoneEgress.
  string resource_mesh = 4;
}

// ClustersResponse is a response containing result of kuma-dp clusters
// execution on Zone CP.
message ClustersResponse {
  // RequestID is a UUID that was set by the Global CP.
  string request_id = 1;

  oneof result {
    // Error that was captured by the Zone CP when executing kuma-dp clusters
    // request.
    string error = 2;
    // The clusters content that is a successful result of kuma-dp clusters
    // execution.
    bytes clusters = 3;
  }
}
